/*
 * @FileName: app_calibration.h
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-08-21 10:50:15
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-11-10 09:11:53
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */

#ifndef __APP_CALIBRTION_H__
#define __APP_CALIBRTION_H__

#include <stdint.h>
#include "bsp_flash.h"

typedef struct
{
    uint16_t k; // 精度0.0001
    int16_t b; // 精度0.0001
} calibration_t;

typedef enum {
    FACTOR_IDX_VIN = 0,
    FACTOR_IDX_IIN,
    FACTOR_IDX_IIN_L,
    FACTOR_IDX_VOUT,
    FACTOR_IDX_IOUT,
    FACTOR_IDX_IOUT_L,
    FACTOR_IDX_NUM
} FACTOR_IDX;

typedef struct
{
    uint16_t version;
    int16_t factoryCode;
    int16_t distVout;
    int16_t distIout;
    int16_t maxIout;
    int16_t maxVout;
    int16_t maxPout;
    calibration_t factor[FACTOR_IDX_NUM];

} fsbb_info_t;



// 合法系数范围
#define FACTOR_K_MAX 12000      // 1.2
#define FACTOR_K_MIN 8000       // 0.8
#define FACTOR_B_MAX 10000      // 1.0
#define FACTOR_B_MIN (-10000)   // -1.0

#define FACTOR_K_DEFAULT 10000  // 1.0
#define FACTOR_B_DEFAULT 0      // 0.0

extern fsbb_info_t fsbb_info;

void app_calib_init(void);
ErrorStatus app_calib_config(uint8_t id, uint16_t k, int16_t b);
void fsbb_info_updata(void);
void calib_reset(void);
char * calib_run(void);
#endif // __APP_CALIBRTION_H__
